    layui.use(['form', 'table', 'laydate', 'element', 'upload'], function(){
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;
    var upload = layui.upload;
    var zhangtao ='110';
    // var element = layui.element;
    var addGoodsCodeUrl = "/general/guojigang/public/index/index/addGoodsCode?zhangtao=110";
    const delGoodsCodeUrl = "/general/guojigang/public/index/index/delGoodsCode";
    var editGoodsCodeUrl = "/general/guojigang/public/index/index/editGoodsCode?zhangtao=110";
    const addHongYanUrl = "/general/guojigang/public/index/index/addHongYan";
    const editHongYanUrl = "/general/guojigang/public/index/index/editHongYan";
    const ajaxGoodsCodeList = "/general/guojigang/public/index/index/ajaxGoodsCodeList";
    var ajaxBomListUrl = "/general/guojigang/public/index/index/ajaxBomList";
    const ajaxHongYanListUrl = "/general/guojigang/public/index/index/ajaxHongYanList";
    const exportExcelUrl = "/general/guojigang/public/index/index/exportData";
    const logUrl = "/general/guojigang/public/index/index/logList";
    const ajaxGetAllInventoryUrl = "/general/guojigang/public/index/index/ajaxGetAll";
    var importExcelUrl = "/general/guojigang/public/index/index/importExcel?zhangtao=110";
    const delAllUrl = "/general/guojigang/public/index/index/delAll";

    //用来存放 每一页 的 所有数据行 ID 的map集合
    var pageDataIdMap;
    //用来存放 我们勾选的数据行 ID 的map集合
    var idMap = new Map();
    form.render('select'); 
    //渲染存货编码
    table.render({
        elem: '#cunhuobm_list'
        ,url: ajaxGoodsCodeList
        ,limits: [10,20,50,100,200,500,1000,99999]
        ,limit: 20 //每页默认显示的数量
        ,response: {
            statusName: 'status'
            ,statusCode: 200
            ,msgName: 'msg'
            ,countName: 'count'
            ,dataName: 'data'
        }
        ,cols: [[
            // {checkbox: true, fixed: true}
            {field:'id', title: 'ID',hide: true}
            ,{field:'code', title: '存货编码'}
            ,{field:'ctime', title: '添加时间', hide: true}
            ,{field:'mtime', title: '修改时间', hide: true}
            ,{field:'state', title: '操作', templet:'#colCunHuoBar', width:200}
        ]]
        ,id: 'cunhuobm_list'
        ,page: true
        ,toolbar:"#headCunHuoBar"
        ,text: { none: '暂无相关数据' }
        ,totalRow:true
        ,done: function (res, curr, count){
            var len = res.data.length;
            //每一页的数据行时,将这一页的所有数据行 ID 保存到 pageDataIdMap 中
            pageDataIdMap = new Map();
              for(var i = 0;i < len;i++){   //填充当前页的数据
                  pageDataIdMap[res.data[i].code] = res.data[i].code;
              }
            var chooseNum = 0;   //记录当前页选中的数据行数
            for(var i = 0;i < len;i++){   //勾选行回显
                for(var key in idMap){
                    if(res.data[i].code == key){
                        res.data[i]["LAY_CHECKED"]='true';
                        //找到对应数据改变勾选样式，呈现出选中效果
                        var index= res.data[i]['LAY_TABLE_INDEX'];
                        $('tr[data-index=' + index + '] input[type="checkbox"]').prop('checked', true);
                        $('tr[data-index=' + index + '] input[type="checkbox"]').next().addClass('layui-form-checked');
                        chooseNum++;
                    }
                }
            }
            if(len != 0 && chooseNum == len){   //表示该页全选  --  全选按钮样式回显
                $('input[lay-filter="layTableAllChoose"]').prop('checked',true);
                $('input[lay-filter="layTableAllChoose"]').next().addClass('layui-form-checked');
            }
        }
    });
    table.on('checkbox(user)', function(obj){
        if(obj.type == 'one'){    //单选操作
            if(obj.checked){     //选中
                idMap[obj.data.code] = obj.data.code;
            }else{      //取消选中
                for(var key in idMap){
                    if(key == obj.data.code){   //移除取消选中的id
                        delete idMap[obj.data.code];
                    }
                }
            }
        }else{      //全选操作
            if(obj.checked){    //选中
                for(var pageKey in pageDataIdMap){
                    idMap[pageKey] = pageKey;
                }
            }else{     //取消选中
                for(var pageKey in pageDataIdMap){
                    for(var key in idMap){
                        if(key == pageKey){
                            delete idMap[pageKey];
                        }
                    }
                }
            }
        }
        // var active = {
        //     getCheckData: function(){
        //         batchSubmitWt();
        //     }
        // };

        // $('.demoTable .layui-btn').on('click', function(){
        //     var type = $(this).data('type');
        //     active[type] ? active[type].call(this) : '';
        //  });
    });
    table.render({
        elem: '#hongyan_list'
        ,url: ajaxHongYanListUrl
        ,response: {
            statusName: 'status'
            ,statusCode: 200
            ,msgName: 'msg'
            ,countName: 'count'
            ,dataName: 'data'
        }
        ,width: '1620'
        ,cols: [[
            {field:'id', title: 'ID', width: '120'}
            ,{field:'code', title: '编码', width: '120'}
            ,{field:'memo', title: '备注', width: '200'}
            ,{field:'buyer', title: '采购员', width: '100'}
            ,{field:'item_name', title: '名称', width:'120'}
            ,{field:'model_no', title: '规格型号', width:'120'}
            ,{field:'unit', title: '单位', width:'100'}
            ,{field:'price_with_tax', title: '含税价格', width:'100'}
            ,{field:'currency_type', title: '币种', width:'80'}
            ,{field:'local_currency', title: '本币价格', width:'100'}
            ,{field:'price_without_tax', title: '不含税价格', width:'100'}
            ,{field:'mtime', title: '更新日期', width:'160'}
            ,{field:'state', title: '操作', templet:'#colHongYanBar', width:'200'}
        ]]
        ,id: 'hongyan_list'
        ,page: true
        ,toolbar:"#hongYanBar"
        ,text: { none: '暂无相关数据' }
        ,totalRow:true
    });

    table.on('radio(user)', function(obj){ //test 是 table 标签对应的 lay-filter 属性
        $("#item_name").val(obj.data.cInvName);
        $("#zjbm").val(obj.data.cInvCode);
        $("#model_no").val(obj.data.cInvStd);
        layer.close(layer.index); 
        // $("#inventory_table").css('display', 'none');
      });
    // 监听账套选择变化
    form.on('select(zhangtao)', function(data) {
        zhangtao = data.value;      // 获取选中的 value（如 "110"）
        ajaxBomListUrl = "/general/guojigang/public/index/index/ajaxBomList?zhangtao="+zhangtao;
        addGoodsCodeUrl = "/general/guojigang/public/index/index/addGoodsCode?zhangtao="+zhangtao;
        editGoodsCodeUrl = "/general/guojigang/public/index/index/editGoodsCode?zhangtao="+zhangtao;
        importExcelUrl = "/general/guojigang/public/index/index/importExcel?zhangtao="+zhangtao;
        var selectedText = data.elem[data.elem.selectedIndex].text; // 获取选中的文本（如 "江西永冠发展"）
        layer.alert("已切换："+selectedText+"账套");
        $("#reload").click();
    });
    table.on('tool(user)', function (obj) {
        switch(obj.event){
            case 'edit':
                layer.open({
                    //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                    type:1,
                    title:"变更数据",
                    content: $("#chbm_edit"),
                    btn: ['更新'], 
                    success:function(){
                        $("#chbm_code").val(obj.data.code); 
                        $("#zhangtao").val(obj.data.zhangtao);                        

                    },
                    yes: function (index, layero) {
                        let id = obj.data.id;
                        let code = $("#chbm_code").val();
                        let zhangtao = $("#zhangtao").val();

                        let para = {
                            id:id, 
                            code:code,
                            zhangtao:zhangtao,

                        };
                        $.ajax({
                            type: "POST",
                            url: editGoodsCodeUrl,
                            data: para,
                            traditional: true, //是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true!!!!!!
                            dataType:"json",
                            success: function(returnData){
                                let state = 0;
                                if (returnData.data.mtime != returnData.data.ctime) {
                                    state = 1;
                                }
                                if(returnData.status == 200){
                                    layer.alert(returnData.msg, {
                                        closeBtn: 0
                                      }, function(){
                                          obj.update({
                                                code:code,
                                                mtime:returnData.data.mtime,
                                                state:state
                                            });
                                            layer.close(layer.index);
                                      });
                                }else{
                                    layer.alert(returnData.msg, {
                                        closeBtn: 0
                                      }, function(){
                                        layer.close(layer.index);
                                      });
                                }
                            }
                        })
                        layer.close(index);
                    }
                });
                break;
            case 'del':
                $.post(delGoodsCodeUrl, {id:obj.data.id}, function(data){
                    // layer.msg(data.msg);
                    if(data.status==200){
                        layer.msg("已删除");
                     $("#reload").click();
                    }


                })
                // layer.confirm('确定删除?', {icon: 3, title: '提示'}, function (index) {
                //     $.post(delGoodsCodeUrl, {id:obj.data.id}, function(data){
                //         layer.msg(data.msg);
                //         if(data.status==200) obj.del();
                //         layer.close(index);
                //     })
                    
                // });
                break;
            case 'hy_edit':
                layer.open({
                    //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                    type:1,
                    title:"变更数据",
                    content: $("#hy_edit"),
                    btn: ['更新'], 
                    success:function(){
                        $("#zjbm").val(obj.data.code);       
                        $("#memo").val(obj.data.memo); 
                        $("#buyer").val(obj.data.buyer);                       
                        $('#currency_type').children('option').each(function(){
                            if($(this).val() == obj.data.currency_type){
                                $(this).prop('selected',true);
                                form.render('select');
                            }
                        });
                        $("#unit").val(obj.data.unit);
                        $("#item_name").val(obj.data.item_name);
                        $("#model_no").val(obj.data.model_no);
                        $("#price_with_tax").val(obj.data.price_with_tax);
                        $("#local_currency").val(obj.data.local_currency);
                        $("#price_without_tax").val(obj.data.price_without_tax);
                    },
                    yes: function (index, layero) {
                        let id = obj.data.id;
                        let code = $("#zjbm").val();
                        let memo = $("#memo").val();
                        let buyer = $("#buyer").val();
                        let unit = $("#unit").val();
                        let item_name = $("#item_name").val();
                        let model_no = $("#model_no").val();
                        let price_with_tax = $("#price_with_tax").val();
                        let currency_type = $("#currency_type").val();
                        let local_currency = $("#local_currency").val();
                        let price_without_tax = $("#price_without_tax").val();
                        if(local_currency === "" || local_currency ==null){
                            layer.alert("本币价格不能为空")
                            return false;
                    　　}
                        if(isNaN(price_with_tax) || !(price_with_tax > 0)){
                            layer.alert("含税价格请输入大于0的金额")
                            return false;
                    　　}
                        if(isNaN(local_currency) || !(local_currency > 0)){　　　　
                            layer.alert("本币价格输入大于0的金额")
                        　　return false; 
                        }
                        if(isNaN(price_without_tax) || !(price_without_tax > 0)){
                            layer.alert("不含税价格请输入大于0的金额")
                            return false;
                    　　}
                        let para = {
                            id:id, 
                            code:code, 
                            memo:memo,
                            buyer:buyer,
                            item_name:item_name,
                            unit:unit,
                            model_no:model_no,
                            price_with_tax: price_with_tax,
                            currency_type: currency_type,
                            local_currency: local_currency,
                            price_without_tax: price_without_tax
                        };
                        $.ajax({
                            type: "POST",
                            url: editHongYanUrl,
                            data: para,
                            traditional: true, //是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true!!!!!!
                            dataType:"json",
                            success: function(returnData){
                                let state = 0;
                                if (returnData.data.mtime != returnData.data.ctime) {
                                    state = 1;
                                }
                                if(returnData.status == 200){
                                    layer.alert(returnData.msg, {
                                        closeBtn: 0
                                      }, function(){
                                          obj.update({
                                                code: returnData.data.code, 
                                                memo: returnData.data.memo,
                                                buyer: returnData.data.buyer,
                                                item_name: returnData.data.item_name,
                                                unit: returnData.data.unit,
                                                model_no: returnData.data.model_no,
                                                price_with_tax: returnData.data.price_with_tax,
                                                currency_type: returnData.data.currency_type,
                                                price_without_tax: returnData.data.price_without_tax,
                                                local_currency: returnData.data.local_currency,
                                                state: state
                                            });
                                            layer.close(layer.index);
                                      });
                                }else{
                                    layer.alert(returnData.msg, {
                                        closeBtn: 0
                                      }, function(){
                                        layer.close(layer.index);
                                      });
                                }
                            }
                        })
                        layer.close(index);
                    }
                });
                break;
            case 'cubm_log':
                showDropDownPanel(logUrl + '?ticket_no=' + obj.data.id + '&action_type=1');
                break;
            case 'hy_log':
                showDropDownPanel(logUrl + '?ticket_no=' + obj.data.id + '&action_type=2');
                break;
        }
    })

    table.on('toolbar(user)', function (obj) {
        switch(obj.event){
            case 'add':
                selectRole(1, '50%', '30%');
                break;
            case 'hy_add':
                selectRole(2, '50%', '90%');
                break;
            case 'search':
                getSearchData();
                break;
            case 'export_excel':
                exportExcelData();
                break;
            case 'delAll':
                layer.confirm('确定<strong style="color: red;">删除全部数据</strong>吗?', {icon: 3, title: '提示'}, function (index) {
                    $.post(delAllUrl, {}, function(data){
                      layer.msg("已删除");
                     $("#reload").click();
                    })
                })
                break;
        }

    })

    function selectRole(type=1, area1='50%', area2='50%'){
        let title, url;
        if (type == 1){
            title = "新增存货编码";
            url = addGoodsCodeUrl;
        } else if(type == 2){
            title = "新增洪研价格";
            url = addHongYanUrl;
        }

        layer.open({
            //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            type:2,
            title:title,
            area: [area1,area2],
            content: url,
            success:function(){
                form.render();
            }
        });
    }

    function getSearchData(){
        
        // let codes = "";
        // for(var key in idMap){
        //     codes += key + ",";
        // }
        // if(codes == ''){
        //     layer.open({title:'提示',content:'请勾选要查询的库存编码'});
        //     return false;
        // }       
        
        // codes = codes.slice(0,-1);
        table.render({
            elem: '#bom_list'
            // ,url: ajaxBomListUrl+'?code='+codes
            ,url: ajaxBomListUrl
            ,limits: [10,20,50,100,200,500,1000,99999]
            ,limit: 20 //每页默认显示的数量
            ,response: {
                statusName: 'status'
                ,statusCode: 200
                ,msgName: 'msg'
                ,countName: 'count'
                ,dataName: 'data'
            }
            ,cols: [[
                {field:'mjdl', title: '母件大类', width:'120'}
                ,{field:'mjbm', title: '母件编码', width:'120'}
                ,{field:'mjmc', title: '母件名称', width:'120'}
                ,{field:'mjchdm', title: '母件存货代码', width:'120'}
                ,{field:'mjggxh', title: '母件规格型号', width:'120'}
                ,{field:'mjjdpf', title: '母件卷到平方', width:'120'}
                ,{field:'mjjldw', title: '母件计量单位', width:'120'}
                ,{field:'zjxh', title: '子件序号', width:'120'}
                ,{field:'zjdl', title: '子件大类', width:'120'}
                ,{field:'zjbm', title: '子件编码', width:'120'}
                ,{field:'zjmc', title: '子件名称', width:'120'}
                ,{field:'zjdm', title: '子件代码', width:'120'}
                ,{field:'zjgg', title: '子件规格', width:'120'}
                ,{field:'zjjdpf', title: '子件卷到平方', width:'120'}
                ,{field:'jldw', title: '计量单位', width:'120'}
                ,{field:'gylx', title: '供应类型', width:'120'}
                ,{field:'jbyl', title: '基本用量', width:'120'}
                ,{field:'jcyl', title: '基础用量', width:'120'}
                // ,{field:'bbwsdj', title: '本币无税单价', edit: 'text', width:'120'}
                // ,{field:'bbwsdj', title: '本币无税单价', width:'120'}
                // ,{field:'zdjg', title: '取价MAX(不含税)', width:'120'}
                // ,{field:'hyjg', title: '洪研价格', edit: 'text', width:'120'}
                // ,{field:'hyjg', title: '洪研价格', width:'120'}
                ,{field:'zf', title: '涨幅', width:'120'}
                ,{field:'dzdsl', title: '打折的数量(膜和胶95%)', width:'120'}
                ,{field:'bompfkz', title: 'BOM平方克重', width:'120'}
                ,{field:'dh', title: '单耗', width:'120'}
                ,{field:'cldj', title: '材料单价', width:'120'}
                ,{field:'dwcbzc', title: '单位成本组成', width:'120'}
                ,{field:'dwcbhj', title: '单位成本合计', width:'120'}
                ,{field:'mjfzdw', title: '母件辅助单位', width:'120'}
                ,{field:'bomfzdwcb', title: 'BOM辅助单位成本(纯专用材料)', width:'120'}
            ]]
            ,id: 'bom_list'
            ,page: true
            ,toolbar:"#bomHeadBar"
            ,text: { none: '暂无相关数据' }
        });
    }

    function exportExcelData(){
        // let codes = "";
        // for(var key in idMap){
        //     codes += key + ",";
        // }
        // if(codes == ''){
        //     layer.open({title:'提示',content:'请先勾选需要导出的库存编码'});
        //     return false;
        // }
        // codes = codes.slice(0,-1);
        let url = exportExcelUrl;
        window.open(url);
    }

    function selectRole1(path, title, area1 = '50%', area2 = '50%'){
            layer.open({
                //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                type:2,
                title:title,
                area: [area1,area2],
                content:path,
                success: function(obj, index){
                    form.render();
                }
            });    
    }

    function showDropDownPanel( path, area1 = '50%', area2 = '50%'){
        layer.open({
            //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            type:2,
            title:'变更日志',
            area: [area1,area2],
            content:path,
            success: function(obj, index){
                form.render();
            }
        });
    }

    var $ = layui.$, active = {
        reload: function(){
          var hyCode = $('#hyCode');
          var hyItemName = $('#itemName');
          var beginDate = $('#ddate1');
          var endDate = $('#ddate2');
          var modelNo = $('#modelNo');

          var chbmReload = $('#chbmReload');
          var addReload = $('#addReload');
          //执行重载
          table.reload('cunhuobm_list', {
            page: {
              curr: 1 //重新从第 1 页开始
            }
            ,where: {
              key: {
                code: chbmReload.val(),
                begin_date: beginDate.val(),
                end_date: endDate.val(),
                zhangtao: zhangtao,

              }
            }
          });

          
          //执行重载
          table.reload('hongyan_list', {
            page: {
              curr: 1 //重新从第 1 页开始
            }
            ,where: {
              key: {
                code: hyCode.val(),
                item_name: hyItemName.val(),
                begin_date: beginDate.val(),
                end_date: endDate.val(),
                model_no: modelNo.val()
              }
            }
          });
        }
    };

    $('.layui-fluid .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
    });

    $('.apply_table .layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    //添加子件编码
    form.on('submit(add-goods-code)', function(data){
        submitData(addGoodsCodeUrl, data);
        return false;
    });

    //编辑子件编码
    form.on('submit(edit-goods-code)', function(data){
        submitData(editGoodsCodeUrl, data);
        return false;
    });

    //添加HongYan价格
    form.on('submit(add-hong-yan)', function(data){
        submitData(addHongYanUrl, data);
        return false;
    });

    //保存HongYan价格
    form.on('submit(edit-hong-yan)', function(data){
        console.log(data);
        // submitData(editHongYanUrl, data);
        return false;
    });

    function submitData(url, data){
        $.ajax({
            type: "POST",
            url: url,
            data: data.field,
            traditional: true, //是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true!!!!!!
            dataType:"json",
            success: function(returnData){
                if(returnData.status == 200){
                        layer.msg("ok~");

                    setTimeout(function() {
                        parent.layer.closeAll(); // 明确关闭页面层
                        parent.$("#reload").click();
                    }, 1000)
                    // layer.alert(returnData.msg, {
                    //     closeBtn: 0
                    //   }, function(){
                    //     window.parent.location.reload();
                    //   });
                }else{
                    layer.alert(returnData.msg, {
                        closeBtn: 0
                      }, function(){
                   layer.msg("ok~");
                    setTimeout(function() {
                        parent.layer.closeAll(); // 明确关闭页面层
                        parent.$("#reload").click();
                    }, 1000)
                      });
                }
            }
        })
    }

    //单元格编辑hongyan价格
    table.on('edit(user)', function(obj){
        let zjbm = obj.data.zjbm;
        let hyjg = obj.data.hyjg;
        let bbwsdj = obj.data.bbwsdj;
        //先保存数据
        $.post(addHongYanUrl, {code:zjbm,price_without_tax:hyjg,local_currency:bbwsdj}, function(){
            // let data2 = table.checkStatus('cunhuobm_list').data
            getSearchData();
        })
    })

    upload.render({
        elem:'.import_btn',
        url:importExcelUrl,
        accept:'file',  //普通文件
        exts:'xlsx',     //允许的文件后缀
        before: function(obj) {
        // 动态添加账套参数
        this.url = "/general/guojigang/public/index/index/importExcel?zhangtao=" + zhangtao;
    },
        done:function(res){
            if(res.status==200){
                alert("处理成功"+res.data+"条数据");
            }
        }
    });

    //常规用法
    laydate.render({
        elem: '#ddate'
    });
    //常规用法
    laydate.render({
        elem: '#ddate1'
    });
    //常规用法
    laydate.render({
        elem: '#ddate2'
    });
    $("#zjbm").click(function(){
        layer.open({
            //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            type:1,
            title:"",
            content: $("#inventory_table"),
            offset:"lt",
            maxWidth: '790',

            success:function(){
                //渲染存货编码
            table.render({
                elem: '#inventory_list'
                ,url: ajaxGetAllInventoryUrl
                ,limit: 10 //每页默认显示的数量
                ,response: {
                    statusName: 'status'
                    ,statusCode: 200
                    ,msgName: 'msg'
                    ,countName: 'count'
                    ,dataName: 'data'
                }
                ,width: '790'
                ,cols: [[ 
                    {field:'RowId', title: 'ID', width: '50'}
                    ,{field:'cInvName', title: '名称', width:'320'}
                    ,{field:'cInvCode', title: '存货编码', width: '120'}
                    ,{field:'cInvStd', title:'规格型号', width: '200'}
                    ,{type: 'radio', width: '100'}
                ]]
                ,id: 'inventory_list'
                ,page: true
                ,text: { none: '暂无相关数据' }
                ,totalRow:true
                ,done: function (res, curr, count){

                    
                }
            });
            form.render();
            }
        });

        $("#hy_search").click(function(){
            var searchCode = $('#search_code');
            var itemName = $('#search_item_name');
            var modelNo = $('#search_model_no');
            if (searchCode.val().length != 0) {
                if (new RegExp("^[\u4e00-\u9fa5]{0,}$").test(searchCode.val())) {
                    layer.alert("字符格式不正确");
                    return false;
                }
            }
            //执行重载
            table.reload('inventory_list', {
                page: {
                curr: 1 //重新从第 1 页开始
                }
                ,where: {
                key: {
                    code: searchCode.val(),
                    item_name: itemName.val(),
                    model_no: modelNo.val()
                }
                }
            });
        })
    })

    form.on('select(currency_type)', function(data){
        $("#price_with_tax").val("");
        $("#local_currency").val("");
        $("#price_without_tax").val("");
    });

    //含税价格变化
    $("#price_with_tax").blur(function(){
        if ($("#currency_type").val() == "") {
            layer.alert("请先选择币种");
            $(this).val("");
            return false;
        }
        if ($("#currency_type").val() == "人民币") {
            let price_without_tax = ($(this).val() / 1.13).toFixed(2);
            //本币价格
            $("#local_currency").val($(this).val());
            //不含税价格
            $("#price_without_tax").val(price_without_tax);
        } else if ($("#currency_type").val() == "美元" || $("#currency_type").val() == "欧元" || $("#currency_type").val() == "日币") {
            let price_with_tax = $(this).val();
            $.ajax({
                type: "GET",
                url:  "/general/guojigang/public/index/index/ajaxFindExchangeRate?name=" + $("#currency_type").val(),
                success: function(returnData){
                    let exchange_rate = parseFloat(returnData.data.nflat);
                    let local_currency1 = (price_with_tax * 1.13 * exchange_rate).toFixed(2);
                    let price_without_tax = (price_with_tax * exchange_rate).toFixed(2);
                    $("#local_currency").val(local_currency1);
                    $("#price_without_tax").val(price_without_tax); 
                }
            })
        }
    })
});


